package cn.edu.sdjzu.xg.eagle.bysj.controller;

import cn.edu.sdjzu.xg.eagle.bysj.annotation.IgnoreAuth;
import cn.edu.sdjzu.xg.eagle.bysj.annotation.SysLog;
import cn.edu.sdjzu.xg.eagle.bysj.entity.QiantuidakaEntity;
import cn.edu.sdjzu.xg.eagle.bysj.entity.view.QiantuidakaView;
import cn.edu.sdjzu.xg.eagle.bysj.service.Interface.QiantuidakaService;
import cn.edu.sdjzu.xg.eagle.bysj.utils.MPUtil;
import cn.edu.sdjzu.xg.eagle.bysj.utils.PageUtils;
import cn.edu.sdjzu.xg.eagle.bysj.utils.R;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.Date;
import java.util.Map;

/**
 * 签退打卡
 * 后端接口
 * @author 
 * @email 
 * @date 2025-06-02 13:29:27
 */
@RestController
@RequestMapping("/qiantuidaka")
public class QiantuidakaController {
    @Autowired
    private QiantuidakaService qiantuidakaService;









    /**
     * 后台列表
     */
    @RequestMapping("/page")
    public R page(@RequestParam Map<String, Object> params, QiantuidakaEntity qiantuidaka,
                  @RequestParam(required = false) @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") Date dakashijianStart,
                  @RequestParam(required = false) @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") Date dakashijianEnd,
                  HttpServletRequest request){
                                    EntityWrapper<QiantuidakaEntity> ew = new EntityWrapper<QiantuidakaEntity>();
                                                                                                                                                                                if(dakashijianStart!=null) ew.ge("dakashijian", dakashijianStart);
                    if(dakashijianEnd!=null) ew.le("dakashijian", dakashijianEnd);
                                    
        
        
        PageUtils page = qiantuidakaService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, qiantuidaka), params), params));
        return R.ok().put("data", page);
    }







    /**
     * 前端列表
     */
	@IgnoreAuth
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params,QiantuidakaEntity qiantuidaka,
                @RequestParam(required = false) @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") Date dakashijianStart,
                @RequestParam(required = false) @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") Date dakashijianEnd,
		HttpServletRequest request){
        EntityWrapper<QiantuidakaEntity> ew = new EntityWrapper<QiantuidakaEntity>();
                if(dakashijianStart!=null) ew.ge("dakashijian", dakashijianStart);
                if(dakashijianEnd!=null) ew.le("dakashijian", dakashijianEnd);

		PageUtils page = qiantuidakaService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, qiantuidaka), params), params));
        return R.ok().put("data", page);
    }

	/**
     * 列表
     */
    @RequestMapping("/lists")
    public R list( QiantuidakaEntity qiantuidaka){
       	EntityWrapper<QiantuidakaEntity> ew = new EntityWrapper<QiantuidakaEntity>();
      	ew.allEq(MPUtil.allEQMapPre( qiantuidaka, MPUtil.camelToSnake("qiantuidaka")));
        return R.ok().put("data", qiantuidakaService.selectListView(ew));
    }

	 /**
     * 查询
     */
    @RequestMapping("/query")
    public R query(QiantuidakaEntity qiantuidaka){
        EntityWrapper< QiantuidakaEntity> ew = new EntityWrapper< QiantuidakaEntity>();
 		ew.allEq(MPUtil.allEQMapPre( qiantuidaka, MPUtil.camelToSnake("qiantuidaka")));
		QiantuidakaView qiantuidakaView =  qiantuidakaService.selectView(ew);
		return R.ok("查询签退打卡成功").put("data", qiantuidakaView);
    }
	
    /**
     * 后端详情
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
        QiantuidakaEntity qiantuidaka = qiantuidakaService.selectById(id);
		qiantuidaka = qiantuidakaService.selectView(new EntityWrapper<QiantuidakaEntity>().eq("id", id));
        return R.ok().put("data", qiantuidaka);
    }

    /**
     * 前端详情
     */
	@IgnoreAuth
    @RequestMapping("/detail/{id}")
    public R detail(@PathVariable("id") Long id){
        QiantuidakaEntity qiantuidaka = qiantuidakaService.selectById(id);
		qiantuidaka = qiantuidakaService.selectView(new EntityWrapper<QiantuidakaEntity>().eq("id", id));
        return R.ok().put("data", qiantuidaka);
    }
    



    /**
     * 后端保存
     */
    @RequestMapping("/save")
    @SysLog("新增签退打卡")
    public R save(@RequestBody QiantuidakaEntity qiantuidaka, HttpServletRequest request){
    	//ValidatorUtils.validateEntity(qiantuidaka);
        qiantuidakaService.insert(qiantuidaka);
        return R.ok();
    }
    
    /**
     * 前端保存
     */
    @SysLog("新增签退打卡")
    @RequestMapping("/add")
    public R add(@RequestBody QiantuidakaEntity qiantuidaka, HttpServletRequest request){
    	//ValidatorUtils.validateEntity(qiantuidaka);
        qiantuidakaService.insert(qiantuidaka);
        return R.ok();
    }



    /**
     * 修改
     */
    @RequestMapping("/update")
    @Transactional
    @SysLog("修改签退打卡")
    public R update(@RequestBody QiantuidakaEntity qiantuidaka, HttpServletRequest request){
        //ValidatorUtils.validateEntity(qiantuidaka);
        qiantuidakaService.updateById(qiantuidaka);//全部更新
        return R.ok();
    }



    

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @SysLog("删除签退打卡")
    public R delete(@RequestBody Long[] ids){
        qiantuidakaService.deleteBatchIds(Arrays.asList(ids));
        return R.ok();
    }

    	









}
